﻿
// JScript 文件
//模态窗口，始终获得焦点，父页面不可编辑
function windowShowModalDialog(url, windowobj, width, height)        //默认高宽500px
{
    var tmpwidth = (width == '') ? 500 : width;
    var tmpheight = (height == '') ? 500 : height;

    var Width = 'dialogWidth=' + tmpwidth + 'px;';
    var Height = 'dialogHeight=' + tmpheight + 'px;';
    var s_Status = 'status=1;';
    var Scroll = 'scroll=1;';
    var rtn = Width + Height + s_Status + Scroll;

    //防止模态窗口缓存增加随机参数
    var dt = new Date();

    if (url.indexOf('?') >= 0) {
        url = url + "&temp=" + dt.getTime();
    }
    else {
        url = url + '?temp=' + dt.getTime();
    }
    //防止模态窗口缓存增加随机参数
    window.showModalDialog(url, windowobj, rtn);
    //window.showModelessDialog(url,windowobj,rtn);
}

function windowDialogArguments() {
    return window.dialogArguments;
}

//非模态窗口，只不过弹出一个页面，还可以操作父窗口。
function windowShowModelessDialog(url, windowobj, Width, Height, Left, Top, IsCenter, Resizable, s_Status, Scroll) {
    var urlstr = url;
    var tmpwidth = (Width == '') ? 500 : Width;
    var tmpheight = (Height == '') ? 500 : Height;
    var tmpleft = (Left == '') ? 500 : Left;
    var tmptop = (Top == '') ? 500 : Top;
    var tmpcenter = (IsCenter == '') ? 1 : IsCenter;
    var tmphresizable = (Resizable == '') ? 0 : Resizable;
    var tmpstatus = (Status == '') ? 1 : s_Status;
    var tmpscroll = (Scroll == '') ? 1 : Scroll;

    var width = 'dialogWidth=' + tmpwidth + 'px;';
    var height = 'dialogHeight=' + tmpheight + 'px;';
    var left = 'dialogLeft=' + tmpleft + 'px;';
    var top = 'dialogTop=' + tmptop + 'px;';
    var iscenter = 'center=' + tmpcenter + ';';
    var resizable = 'resizable=' + tmphresizable + ';';
    var newstatus = 'status=' + tmpstatus + ';';
    var scroll = 'scroll=' + tmpscroll;
    var rtn = width + height + left + top + iscenter + resizable + newstatus + scroll;

    //防止模态窗口缓存增加随机参数
    var dt = new Date();

    if (url.indexOf('?') >= 0) {
        url = url + "&temp=" + dt.getTime();
    }
    else {
        url = url + '?temp=' + dt.getTime();
    }
    //防止模态窗口缓存增加随机参数

    window.showModelessDialog(url, windowobj, rtn);
}


function closeWin() {
    window.close();
}
function closeWinAndReload() {
    window.close();
    var parent = window.dialogArguments;
    if (parent && parent.loadpage) {
        parent.loadpage();
    }
}
/*  
将String类型解析为Date类型.  
parseDate('2006-1-1') return new Date(2006,0,1)  
parseDate(' 2006-1-1 ') return new Date(2006,0,1)  
parseDate('2006-1-1 15:14:16') return new Date(2006,0,1,15,14,16)  
parseDate(' 2006-1-1 15:14:16 ') return new Date(2006,0,1,15,14,16);  
parseDate('2006-1-1 15:14:16.254') return new Date(2006,0,1,15,14,16,254)  
parseDate(' 2006-1-1 15:14:16.254 ') return new Date(2006,0,1,15,14,16,254)  
parseDate('不正确的格式') retrun null  
*/
function parseDate(str) {
    if (typeof str == 'string') {
        var results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) *$/);
        if (results && results.length > 3)
            return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]));
        results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/);
        if (results && results.length > 6)
            return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]));
        results = str.match(/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2})\.(\d{1,9}) *$/);
        if (results && results.length > 7)
            return new Date(parseInt(results[1]), parseInt(results[2]) - 1, parseInt(results[3]), parseInt(results[4]), parseInt(results[5]), parseInt(results[6]), parseInt(results[7]));
    }
    return null;
}

/*  
将Date/String类型,解析为String类型.  
传入String类型,则先解析为Date类型  
不正确的Date,返回 ''  
如果时间部分为0,则忽略,只返回日期部分.  
*/
function formatDate(v) {
    var d = v;
    if (typeof v == 'string') v = parseDate(v);
    if (v instanceof Date) {
        var y = v.getFullYear();
        var m = v.getMonth() + 1;
        var d = v.getDate();
        var h = v.getHours();
        var i = v.getMinutes();
        var s = v.getSeconds();
        var ms = v.getMilliseconds();
        if (ms > 0) return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s + '.' + ms;
        if (h > 0 || i > 0 || s > 0) return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
        return y + '-' + m + '-' + d;
    }
    return d;
}

String.prototype.len = function () {
    return this.replace(/[^\x00-\xff]/g, "**").length;
}

//var realkey=String.fromCharCode(event.keyCode);
//if(event.keyCode==32){realkey='\' 空格\''}
//if(event.keyCode==13){realkey='\' 回车\''}
//if(event.keyCode==27){realkey='\' Esc\''}
//if(event.keyCode==16){realkey='\' Shift\''}
//if(event.keyCode==17){realkey='\' Ctrl\''}
//if(event.keyCode==18){realkey='\' Alt\''}

function CheckLength(arguments, ilen, e) {
    //var e = window.event ? window.event : e;
    //alert(e.keyCode);
    //if(e.keyCode != 9 || e.keyCode != 8 || e.keyCode != 13 || e.keyCode != 16 || e.keyCode != 17 || e.keyCode != 18 || e.keyCode != 46 || e.keyCode != 36 || e.keyCode != 35 ){
    if (arguments.value.len() <= ilen) {
        return true;
    }
    else {
        return false;
    }
    //}
    //return false;
}

//function ShowInfo(name, url) {
//    top.frames["frmright"].addTabRefrush(name, url);
//}

//查询条件里面开始日期大于等于截止日期不可以查询
function DateCompare(startTime, endTime) {
    if (startTime != null && startTime != "" && startTime != "undefined" && endTime != null && endTime != "" && endTime != "undefined") {
        startTime = startTime.replace(/-/g, "/");
        endTime = endTime.replace(/-/g, "/");
        var num = Date.parse(startTime) - Date.parse(endTime);
        if (num > 0) {
            return false;
        }
        else {
            return true;
        }
    }
    else {
        return true;
    }
}


